home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / stdvga.asm < prev    next >
Assembly Source File  |  1993-12-06  |  11KB  |  381 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file STDVGA.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. include grdriver.inc
  18. cseg    segment byte public 'code'
  19.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  20.  
  21.  
  22. ;--------------------------------------------------------------------------
  23. ; DRIVER HEADER
  24. ;  The following entries MUST match the structure and constant
  25. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  26. ;  The mode word should contain the following bitfields:
  27. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  28. ;     - the adapter type field should be specified
  29. ;     - the memory size field should be specified
  30. ;     - the paging mode field should be specified
  31. ;  The mode set routine will OR in the plane bitfield as it will
  32. ;  change when different color number modes are requested.
  33. ;--------------------------------------------------------------------------
  34.  
  35.     dw    offset mode_set_routine
  36.     dw    offset paging_routine
  37. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_256K+GRD_RW_64K
  38. ;
  39. ; The 'def_xx' fields are filled in by go32 from the corresponding
  40. ; fields of the 'GO32' environment variable
  41. ;
  42. def_tw  dw    80        ; text width
  43. def_th  dw    25        ; text height
  44. def_gw  dw    640        ; graphics width
  45. def_gh  dw    480        ; graphics height
  46. def_nc  dw    16        ; graphics colors
  47.     dw    offset driver_init_routine
  48.     dw    offset text_mode_table
  49.     dw    offset graphics_mode_table
  50.  
  51. ;
  52. ; Biggest text and graphics sizes
  53. ;
  54. Max_TW  equ    80
  55. Max_TH  equ    50
  56. Max_GWn equ    640        ; non interlaced!!!
  57. Max_GHn equ    480
  58. Max_GW  equ    640        ; may be interlaced
  59. Max_GH  equ    480
  60.  
  61.  
  62. ;--------------------------------------------------------------------------
  63. ; TABLE OF SUPPORTED TEXT MODES
  64. ;    - keep sorted by size
  65. ;    - end with an all 0 entry
  66. ;    - BIOS field = 0xff disables it
  67. ;    - fields:
  68. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  69. ;--------------------------------------------------------------------------
  70. text_mode_table        label word
  71.     dw    80,    25,    2,    007h +  00000h
  72.     dw    40,    25,    16,    001h +  00000h
  73.     dw    80,    25,    16,    003h +  00000h
  74.     dw    80,    28,    16,    003h +  00100h
  75.     dw    80,    50,    16,    003h +  00200h
  76.     dw    0,    0,    0,    000h +  00000h
  77.  
  78.  
  79. ;--------------------------------------------------------------------------
  80. ; TABLE OF SUPPORTED GRAPHICS MODES
  81. ;    - keep sorted first by colors then by size
  82. ;    - end with an all 0 entry
  83. ;    - BIOS field = 0xff disables it
  84. ;    - fields:
  85. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  86. ;--------------------------------------------------------------------------
  87. graphics_mode_table    label word
  88.     dw    320,    200,    16,    00dh +  00000h
  89.     dw    640,    200,    16,    00eh +  00000h
  90.     dw    640,    350,    16,    010h +  00000h
  91.     dw    640,    480,    16,    012h +  00000h
  92.     dw    320,    200,    256,    013h +  00000h
  93.     dw    320,    240,    256,    0ffh +  00300h  ; MODE X (to be done)
  94.     dw    360,    480,    256,    0ffh +  00300h  ; MODE X (to be done)
  95.     dw    0,    0,    0,    000h +  00000h
  96.  
  97.  
  98. ;--------------------------------------------------------------------------
  99. ; TABLE OF SPECIAL SETUP PROCEDURES
  100. ;  You may need such procedures for:
  101. ;     -- reloading fonts on standard EGA or VGA for
  102. ;     higher resolution text modes
  103. ;     -- enable HiColor mode of some Super VGAs
  104. ;     -- Handle the parameter passing conventions of the VESA BIOS
  105. ;     -- put VGA into 256 color plane mode ("MODE X")
  106. ;     -- etc...
  107. ;  There should be one entry in the table for every non-zero
  108. ;  'setup_procedure_index' in the text and graphics mode tables.
  109. ;  The first entry in the table belongs to index 100h, and so on.
  110. ;  The special setup procedure is invoked via a near call.
  111. ;
  112. ;  Entry: DI=address of the mode record from the text or graphics
  113. ;      table to set up.
  114. ;
  115. ;  Exit:  Adapter configured
  116. ;      BX=driver mode word as it should be returned by the mode set
  117. ;         routine. Typically it involves picking up the mode word
  118. ;         from the header and OR-ing in the appropriate bitplane mode
  119. ;         bitfield. (This is not needed for text modes)
  120. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  121. ;
  122. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  123. ;--------------------------------------------------------------------------
  124. special_setup_table    label word
  125.     dw    offset  VGA_28row_mode_set
  126.     dw    offset  VGA_50row_mode_set
  127.     dw    offset  VGA_MODE_X_set
  128.  
  129. ;
  130. ; Routine to set up VGA 50 row mode
  131. ; interface is described above
  132. ;
  133. VGA_50row_mode_set    proc    near
  134.     mov    ax,03h            ; set 80x25 mode
  135.     int    10h
  136.     xor    bx,bx
  137.     mov    ax,1112h        ; load 8x8 font
  138.     int    10h
  139.     ret
  140. VGA_50row_mode_set    endp
  141.  
  142. VGA_28row_mode_set    proc    near
  143.     mov    ax,03h            ; set 80x25 mode
  144.     int    10h
  145.     xor    bx,bx
  146.     mov    ax,1111h        ; load 8x14 font
  147.     int    10h
  148.     ret
  149. VGA_28row_mode_set    endp
  150.  
  151. ;
  152. ; Routine to set up VGA 256 color plane mode ("MODE X")
  153. ; interface is described above
  154. ; TO BE COMPLETED
  155. ;
  156. VGA_MODE_X_set        proc    near
  157.     mov    bx,mode_W
  158.     or    bx,GRD_8_X_PLANES
  159.     ret
  160. VGA_MODE_X_set        endp
  161.  
  162.  
  163. ;--------------------------------------------------------------------------
  164. ; DRIVER INIT ROUTINE
  165. ;  called once after the driver is loaded
  166. ;  may do one or more of the followings:
  167. ;    - check for proper board type
  168. ;    - check amount of RAM on board, and:
  169. ;    -- update word in header to reflect correct amount
  170. ;    -- disable modes in the tables for which there is not enough RAM
  171. ;    - check for special equipment (HiColor DAC, etc...)
  172. ;
  173. ;  Entry: nothing
  174. ;
  175. ;  Exit:  AX=status:
  176. ;       non-zero: OK,
  177. ;       0: something went wrong (e.g. wrong adapter, etc..)
  178. ;      BX,CX,DX may be trashed
  179. ;
  180. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  181. ;--------------------------------------------------------------------------
  182. driver_init_routine    proc    far
  183.     mov    ax,1
  184.     ret
  185. driver_init_routine    endp
  186.  
  187.  
  188. ;--------------------------------------------------------------------------
  189. ; MODE SET ROUTINE
  190. ;  sets up a text or graphics mode as close as possible to the one
  191. ;  reguested by the user with regard to number of colors and size.
  192. ;
  193. ;  Entry: AX=mode selection
  194. ;     0 = 80x25 text
  195. ;     1 = default text
  196. ;     2 = text CX cols by DX rows
  197. ;     3 = biggest text
  198. ;     4 = 320x200 graphics
  199. ;     5 = default graphics
  200. ;     6 = graphics CX width by DX height
  201. ;     7 = biggest non-interlaced graphics
  202. ;     8 = biggest graphics
  203. ;     9 = graphics BX colors, CX width by DX height
  204. ;
  205. ;  Exit: BX=driver mode flag
  206. ;     CX=width (in pixels or characters)
  207. ;     DX=height
  208. ;
  209. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  210. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  211. ;     MUCH TABLE DRIVEN
  212. ;--------------------------------------------------------------------------
  213. mode_set_routine    proc    far
  214.     push    ds
  215.     push    di
  216.     push    si
  217.     mov    si,cs
  218.     mov    ds,si
  219.     cmp    ax,9
  220.     jbe    DoIt
  221.     jmp    Exit
  222. DoIt:    add    ax,ax
  223.     mov    si,ax
  224.     jmp    WORD PTR mode_set_table[si]
  225. mode_set_table  label    word
  226.     dw    offset mode_0
  227.     dw    offset mode_1
  228.     dw    offset mode_2
  229.     dw    offset mode_3
  230.     dw    offset mode_4
  231.     dw    offset mode_5
  232.     dw    offset mode_6
  233.     dw    offset mode_7
  234.     dw    offset mode_8
  235.     dw    offset mode_9
  236. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  237.     mov    bx,def_nc
  238.     mov    cx,80
  239.     mov    dx,25
  240.     jmp    Lookup
  241. mode_1: mov    si,offset text_mode_table    ; default text
  242.     mov    bx,def_nc
  243.     mov    cx,def_tw
  244.     mov    dx,def_th
  245.     jmp    Lookup
  246. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  247.     mov    bx,def_nc
  248.     jmp    Lookup
  249. mode_3: mov    si,offset text_mode_table    ; biggest text
  250.     mov    bx,def_nc
  251.     mov    cx,Max_TW
  252.     mov    dx,Max_TH
  253.     jmp    Lookup
  254. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  255.     mov    bx,def_nc
  256.     mov    cx,320
  257.     mov    dx,200
  258.     jmp    Lookup
  259. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  260.     mov    bx,def_nc
  261.     mov    cx,def_gw
  262.     mov    dx,def_gh
  263.     jmp    Lookup
  264. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  265.     mov    bx,def_nc
  266.     jmp    Lookup
  267. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  268.     mov    bx,def_nc
  269.     mov    cx,Max_GWn
  270.     mov    dx,Max_GHn
  271.     jmp    Lookup
  272. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  273.     mov    bx,def_nc
  274.     mov    cx,Max_GW
  275.     mov    dx,Max_GH
  276.     jmp    Lookup
  277. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  278. ;
  279. ; At this point:
  280. ;   SI points to the table to search (text or graphics)
  281. ;   BX has colors
  282. ;   CX has width
  283. ;   DX has height
  284. ;
  285. Lookup: xor    ax,ax                ; last color number seen
  286. Find_C: cmp    [si+4],ax            ; last color number == this?
  287.     je    Same_C
  288.     jb    Prev_C                ; end of table -- use last color
  289.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  290.     je    Prev_C                ; not -- use last color
  291.     mov    ax,[si+4]            ; record color number
  292.     mov    di,si                ; start of entries w/ this color
  293.     cmp    ax,bx                ; enough colors ?
  294.     jae    Find_S
  295. Same_C: add    si,8
  296.     jmp    Find_C
  297. Prev_C: or    ax,ax                ; found any color at all?
  298.     je    Exit
  299. ;
  300. ; At this point:
  301. ;   DI points into the table to the first entry with the desired color
  302. ;      number (either it has enough colors or it is the highest color
  303. ;      number supported by the driver). Additionally, at least the
  304. ;      first (= smallest size) entry for this color is valid (has a
  305. ;      valid BIOS number).
  306. ;   AX has the color number adjusted for the driver
  307. ;   CX has width
  308. ;   DX has height
  309. ;
  310. Find_S: cmp    [di+4],ax            ; still the same color #?
  311.     jne    Prev_S
  312.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  313.     je    Prev_S
  314.     cmp    [di],cx
  315.     jb    Next_S
  316.     cmp    [di+2],dx
  317.     jae    GotIt
  318. Next_S: add    di,8
  319.     jmp    Find_S
  320. Prev_S: sub    di,8
  321. ;
  322. ; At this point:
  323. ;   DI points to the table entry we want to set up
  324. ;
  325. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  326.     or    ah,ah                ; special ?
  327.     je    doBIOS
  328.     mov    al,ah
  329.     xor    ah,ah
  330.     dec    ax
  331.     add    ax,ax
  332.     mov    si,ax
  333.     call    WORD PTR special_setup_table[si]
  334.     jmp    RetVal
  335. doBIOS: int    10h
  336.     mov    bx,GRD_1_PLANE
  337.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  338.     je    doFLAG
  339.     mov    bx,GRD_4_PLANES
  340.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  341.     je    doFLAG
  342.     mov    bx,GRD_8_PLANES
  343.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  344.     je    doFLAG
  345.     mov    bx,GRD_16_PLANES
  346.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  347.     je    doFLAG
  348.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  349. doFLAG: or    bx,mode_W
  350. RetVal: mov    cx,[di]
  351.     mov    dx,[di+2]
  352. Exit:    pop    si
  353.     pop    di
  354.     pop    ds
  355.     ret
  356. mode_set_routine    endp
  357.  
  358.  
  359. ;--------------------------------------------------------------------------
  360. ; PAGING ROUTINE
  361. ;
  362. ;  Entry: AH=read page
  363. ;      AL=write page
  364. ;
  365. ;  Exit: VGA configured.
  366. ;     AX,BX,CX,DX,SI,DI may be trashed
  367. ;
  368. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  369. ;     This code must be relocatable and may not reference any data!
  370. ;--------------------------------------------------------------------------
  371.     assume  ds:nothing, es:nothing
  372.  
  373. paging_routine  proc    far
  374.     ret
  375. paging_routine  endp
  376.  
  377.  
  378. cseg    ends
  379.     end
  380.  
  381.